import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.geom.Line2D;


public class Element {

	int WIDTH;
	int HEIGHT;
	String type;
	Image im;
	Rectangle r;
	Line2D l;
	
	//Movable instance variable
	double xTime;
	double yTime;
	
	double yVel;
	double xVel;
	
	boolean moveable;
	
	int initX = -500;
	int initY = -500;
	int finalX;
	int finalY;
	
	public Element(int x, int y, int width, int height, String s, Image m)
	{
		WIDTH = width;
		HEIGHT = height;
		im = m;
		type = s;
		r = new Rectangle(x,y,width,height);
	}
	
	
	public Element(Element original)
	{
		WIDTH = original.WIDTH;
		HEIGHT = original.HEIGHT;
		im = original.im;
		type = original.type;
		r = new Rectangle(original.r);
	}
	
	
	public String getType()
	{
		return type;
	}
	
	public int getWidth()
	{
		return WIDTH;
	}
	
	public int getHeight()
	{
		return HEIGHT;
	}
	
	public String compileMovement()
	{
		String s = "";
 
		if(moveable)
		{
			if(finalX > initX)
				s += (", " + (finalX-initX));
			else s += (", " + (initX-finalX));
			
			if(finalY > initY)
				s += (", " + (finalY-initY));
			else s += (", " + (initY-finalY));
			
			s += (", " + xVel + ", "  + yVel);
		}
		
		
		return s;
	}
	
	
	public void draw(Graphics g, Applet myApplet)
	{
		g.drawImage(im, r.x, r.y, myApplet);
		
		if(moveable)
		{
			g.drawLine(initX, initY, finalX, finalY);
		}
	}
	
	public Rectangle getRectangle()
	{
		return r;
	}
	
	public boolean getMoveable()
	{
		return moveable;
	}
	
	public void setLoc(int x, int y)
	{
		r.setLocation(x, y);
	}
	
	public void setInitialPos(int x, int y)
	{
		initX = x;
		initY = y;
	}
	
	public void setMovement(int cX, int cY)
	{
		moveable = true;
		finalX = cX;
		finalY = cY;
		
		if(finalX > initX)
			xVel = 1;
		else xVel = -1;
		
		if(finalY > initY)
			yVel = .5;
		else yVel = -.5;
	}
}
